//
//  HttpRequestHelper.m
//  MengCP
//
//  Created by Gideon on 16/4/27.
//  Copyright © 2016年 LiZhenning. All rights reserved.
//

#import "HttpRequestHelper.h"
#import "AFNetworking.h"

@implementation HttpRequestHelper


+ (NSString *)returnErrorMsgError:(NSError *)error{
    
    NSString *msg=nil;
    if (error.code == -1009) {
        return @"网络请求失败，请检查您的网络";
    }
    
    msg =[[NSJSONSerialization JSONObjectWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] options:NSJSONReadingMutableContainers error:nil]valueForKey:@"message"];
    
    return msg;
    
}

+ (NSString *)returnErrorStatusCodeError:(NSError *)error{
    
    NSString *status_code = nil;
    
    if (error.code == -1009) {
        return @"999";
    }
    
    status_code =[[NSJSONSerialization JSONObjectWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] options:NSJSONReadingMutableContainers error:nil]valueForKey:@"status_code"];
    
    return status_code;
    
}

+ (void)returnErrorStatusCodeOverTime:(NSError *)error{
    
    if (error.code == NetWorkStateNone) {
        return ;
    }
    
    NSString *code=[[NSJSONSerialization JSONObjectWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] options:NSJSONReadingMutableContainers error:nil]valueForKey:@"status_code"];
    
    [LoginCorrelationHelper loginCorrelationHelperLoginOverTime:code];
}

+ (void)requestApiServerInfoApp_ver:(NSString *)app_ver Block:(void(^)(NSString *msg))block{
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
    
    [params setObject:app_ver forKey:@"app_ver"];
    
    [manager POST:@"http://api.38ch.com/api/server/info" parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
    
            [[UserCenterUrl shareInstance]  initWithDictionary:responseObject[@"data"]];
            
            if (block)
                block(SUCCESS);
            
        }else{
            
            [[UserCenterUrl shareInstance] initWithData];
            
            if (block)
                block(@"");
        }
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
   
    }];
    
    
}


+(void)requestApiAuthCodeMobile:(NSString *)mobile check:(NSInteger)check Block:(void(^)(NSString *code, NSString *msg))block{
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
    
    [params setObject:mobile forKey:@"mobile"];
    [params setObject:@(check) forKey:@"check"];
    
    [manager POST:[UserCenterUrl shareInstance].URL_API_VCODE parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            NSString * code = [responseObject valueForKey:@"data"];
            
            if (block)
                block(code,SUCCESS);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(nil,msg);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(@"",msg);
    }];
    
    
}

+(void)requestApiRegisterMobile:(NSString *)mobile
                       nickname:(NSString *)nickname
                       password:(NSString *)password
                          vcode:(NSString *)vcode
                          Block:(void(^)(NSString *msg,NSString * infoMsg))block{
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
    
    [params setObject:mobile forKey:@"mobile"];
    [params setObject:nickname forKey:@"nickname"];
    [params setObject:password forKey:@"password"];
    [params setObject:vcode forKey:@"vcode"];
    
    [manager POST:[UserCenterUrl shareInstance].URL_API_REGISTER parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            NSString * message = responseObject[@"msg"];
            
            if (block)
                block(SUCCESS,message);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,msg);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,msg);
    }];
    
    
}

+(void)requestApiLoginMobile:(NSString *)mobile
                    password:(NSString *)password
                        type:(NSString *)type
                       vcode:(NSString * )vcode
                       Block:(void(^)(NSString *msg,NSString * infoMsg,UserModel * model))block{
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
    
    [params setObject:mobile forKey:@"mobile"];
    [params setObject:type forKey:@"type"];
    
    if (password.length != 0) {
        
        [params setObject:password forKey:@"password"];
    }
    
    if (vcode.length != 0) {
        
        [params setObject:vcode forKey:@"vcode"];
    }
    
    
    NSLog(@"%@",params);
    
    [manager POST:[UserCenterUrl shareInstance].URL_API_LOGIN parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            NSString * message = responseObject[@"msg"];
            
            UserModel * model = [UserModel initWithDictionary:responseObject[@"data"]];
            
            [UserCenterHelper shareInstance].token = model.token;
            [UserCenterHelper shareInstance].userModel = model;
            
            NSLog(@"token:%@",model.token);
            
            
            if (block)
                block(SUCCESS,message,model);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,msg,nil);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,msg,nil);
    }];
    
}

+(void)requestApiLoginChpwdMobile:(NSString *)mobile
                       repassword:(NSString *)repassword
                         password:(NSString *)password
                            vcode:(NSString * )vcode
                            Block:(void(^)(NSString *msg,NSString * infoMsg))block{
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setObject:mobile forKey:@"mobile"];
    [params setObject:repassword forKey:@"repassword"];
    
    if (password.length != 0) {
        
        [params setObject:password forKey:@"password"];
    }
    
    if (vcode.length != 0) {
        
        [params setObject:vcode forKey:@"vcode"];
    }
    
    
    [manager POST:[UserCenterUrl shareInstance].URL_LOGIN_CHPWD parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            NSString * message = responseObject[@"msg"];
            
            
            if (block)
                block(SUCCESS,message);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,msg);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,msg);
    }];
    
    
}

+(void)requestApiLogoutBlock:(void(^)(NSString *msg))block{
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    NSString * token = [UserCenterHelper shareInstance].token;
    
    NSMutableDictionary * params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setObject:token forKey:@"token"];
    
    [manager POST:[UserCenterUrl shareInstance].URL_LOGOUT parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            if (block)
                block(SUCCESS);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg);
    }];
    
    
}

+(void)requestApiUserEditIntro:(NSString *)intro
                      nickname:(NSString *)nickname
                          addr:(NSString *)addr
                          area:(NSString *)area
                        avatar:(UIImage *)avatar
                        mobile:(NSString *)mobile
                         Block:(void(^)(NSString *msg,UserModel * model))block{
    
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    NSString * token = [UserCenterHelper shareInstance].token;
    
    NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithCapacity:0];
    
    [dic setObject:token forKey:@"token"];
    
    if (intro.length != 0) {
        
        [dic setObject:intro forKey:@"intro"];
    }
    
    if (nickname.length != 0) {
        
        [dic setObject:nickname forKey:@"nickname"];
    }
    
    if (addr.length != 0) {
        
        [dic setObject:addr forKey:@"addr"];
    }
    
    if (area.length != 0) {
        
        [dic setObject:area forKey:@"area"];
    }
    
    if (avatar) {
        
        
        NSData *imageData = UIImageJPEGRepresentation(avatar, 0.6);
        
        NSString *dataStr = [imageData base64EncodedStringWithOptions:0];
        
        NSString * base64Image = [NSString stringWithFormat:@"image/png;base64,%@",dataStr];
        
        [dic setObject:base64Image forKey:@"avatar"];
        
    }
    
    if (mobile.length != 0) {
        
        [dic setObject:mobile forKey:@"mobile"];
    }
    

    
    [manager POST:[UserCenterUrl shareInstance].URL_USER_EDIT parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            UserModel * model = [UserModel initWithDictionary:responseObject[@"data"]];
            [UserCenterHelper shareInstance].userModel = model;
            
             NSLog(@"token:%@",model.token);
            
            NSUserDefaults * defaults=[NSUserDefaults standardUserDefaults];
            [defaults setObject:model.userDic forKey:USER_DIC];
            [defaults synchronize];
            
            if (block)
                block(SUCCESS,model);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,nil);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,nil);
    }];
    
    
}

+(void)requestApiNewsType:(NSInteger)type
                     page:(NSInteger)page
                     nums:(NSInteger)nums
                    Block:(void(^)(NSString *msg,NSArray * array))block{
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    
    NSMutableDictionary * params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setObject:@(type) forKey:@"type"];
    [params setObject:@(page) forKey:@"page"];
    [params setObject:@(nums) forKey:@"nums"];
    
    [manager POST:[UserCenterUrl shareInstance].URL_API_NEWS parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            NSArray * array = responseObject[@"data"];
            NSMutableArray * temp = [NSMutableArray array];
            
            for (NSDictionary * item in array) {
                
                NewsIndexModel * model = [NewsIndexModel initWithDictionary:item];
                
                [temp addObject:model];
                
            }
            
            if (block)
                block(SUCCESS,temp);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,nil);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,nil);
    }];
    
}

+(void)requestApiNewsDetailsId:(NSString *)Id
                         Block:(void(^)(NSString *msg,NewsIndexModel * model))block{
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    
    NSMutableDictionary * params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setObject:Id forKey:@"id"];
    
    [manager POST:[UserCenterUrl shareInstance].URL_API_NEWS_DETAILS parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            NSDictionary * dic = responseObject[@"data"];
            NewsIndexModel * model = [NewsIndexModel initWithDictionary:dic];
            
            if (block)
                block(SUCCESS,model);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,nil);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,nil);
    }];
    
}

/**
 发起评论
 
 @param msg
 @param news_id
 @param block
 */
+(void)requestApiCommentAddMsg:(NSString *)msg
                       news_id:(NSString *)news_id
                         Block:(void(^)(NSString *msg,NSString * infoMsg))block{
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    NSString * token = [UserCenterHelper shareInstance].token;
    
    NSMutableDictionary * params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setObject:msg forKey:@"msg"];
    [params setObject:news_id forKey:@"news_id"];
    [params setObject:token forKey:@"token"];
    
     NSLog(@"%@",params);

    
    [manager POST:[UserCenterUrl shareInstance].URL_API_COMMENT_ADD parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            NSString * infomsg = responseObject[@"msg"];
            
            if (block)
                block(SUCCESS,infomsg);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,msg);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,msg);
    }];
    
}


/**
 评论点赞
 
 @param opt
 @param comment_id
 @param block
 */
+(void)requestApiCommentOpt:(NSString *)opt
                 comment_id:(NSString *)comment_id
                      Block:(void(^)(NSString *msg))block{
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    
    NSString * token = [UserCenterHelper shareInstance].token;
    
    NSMutableDictionary * params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setObject:opt forKey:@"opt"];
    [params setObject:comment_id forKey:@"comment_id"];
    [params setObject:token forKey:@"token"];
    NSLog(@"%@",params);

    
    [manager POST:[UserCenterUrl shareInstance].URL_API_COMMENT_OPT parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            
            if (block)
                block(SUCCESS);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg);
    }];
    
}



/**
 评论列表
 
 @param page
 @param nums
 @param news_id
 @param block
 */
+(void)requestApiCommentPage:(NSInteger)page
                        nums:(NSInteger)nums
                     news_id:(NSString *)news_id
                       Block:(void(^)(NSString *msg,NSArray * array))block{
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    NSString * token = [UserCenterHelper shareInstance].token;
    
    NSMutableDictionary * params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setObject:@(page) forKey:@"page"];
    [params setObject:@(nums) forKey:@"nums"];
    [params setObject:news_id forKey:@"news_id"];
    
    if (token.length != 0) {
        
        [params setObject:token forKey:@"token"];
        NSLog(@"%@",token);
    }
    
     NSLog(@"%@",params);
    
    [manager POST:[UserCenterUrl shareInstance].URL_API_COMMENT parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            NSArray * array = responseObject[@"data"];
            NSMutableArray * temp = [NSMutableArray array];
            
            for (NSDictionary * item in array) {
                
                CommentIndexModel * model = [CommentIndexModel initWithDictionary:item];
                
                [temp addObject:model];
            }
            
            
            if (block)
                block(SUCCESS,temp);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,nil);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,nil);
    }];
    
    
}

+(void)requestApiFeedbackMobile:(NSString *)mobile
                            msg:(NSString *)msg
                          Block:(void(^)(NSString *msg))block{
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    NSMutableDictionary * params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setObject:msg forKey:@"msg"];
    
    if (mobile.length != 0) {
        
        [params setObject:mobile forKey:@"mobile"];
    }
    
    [manager POST:[UserCenterUrl shareInstance].URL_API_FEEDBACK parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            if (block)
                block(SUCCESS);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg);
        }
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg);
    }];
    
    
}


+(void)requestApiConfigureBlock:(void(^)(NSString *msg,ConfigureModel * model))block{
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    [manager POST:[UserCenterUrl shareInstance].URL_API_CONFIGURE parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            NSDictionary * dic = responseObject[@"data"];
            ConfigureModel * model = [ConfigureModel initWithDictionary:dic];
            [UserCenterHelper shareInstance].configureModel = model;
            
            if (block)
                block(SUCCESS,model);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,nil);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,nil);
    }];
    
    
}

+(void)requestApiBannerNums:(NSInteger)nums
                      Block:(void(^)(NSString *msg,NSArray * array,NSArray * arrayURL))block{
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    NSMutableDictionary * params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setObject:@(nums) forKey:@"nums"];
    
    
    [manager POST:[UserCenterUrl shareInstance].URL_API_BANNER parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            NSArray * array = responseObject[@"data"];
            NSMutableArray * temp = [NSMutableArray array];
            NSMutableArray * sTemp = [NSMutableArray array];
            
            for (NSDictionary * item in array) {
                
                HomeSliderModel * model = [HomeSliderModel initWithDictionary:item];
                [temp addObject:model];
                [sTemp addObject:model.pic_url];
                
            }
            
            if (block)
                block(SUCCESS,temp,sTemp);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,nil,nil);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,nil,nil);
    }];
    
}

+(void)requestApiTeacherPage:(NSInteger)page
                        nums:(NSInteger)nums
                       Block:(void(^)(NSString *msg,NSArray * array))block{
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    NSMutableDictionary * params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setObject:@(page) forKey:@"page"];
    [params setObject:@(nums) forKey:@"nums"];
    
    [manager POST:[UserCenterUrl shareInstance].URL_API_TEACHER parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            NSArray * array = responseObject[@"data"];
            NSMutableArray * temp = [NSMutableArray array];
            
            for (NSDictionary * item in array) {
                
                TeacherIndexModel * model = [TeacherIndexModel initWithDictionary:item];
                
                [temp addObject:model];
                
            }
            
            if (block)
                block(SUCCESS,temp);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,nil);
        }
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,nil);
    }];
    
}

+(void)requestApiHomeDataTag:(NSInteger)tag
                        page:(NSInteger)page
                        nums:(NSInteger)nums
                       Block:(void(^)(NSString *msg,NSArray * array))block{
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    NSMutableDictionary * params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setObject:@(page) forKey:@"page"];
    [params setObject:@(nums) forKey:@"nums"];
    
    
    NSString * url = @"";
    
    if (tag == 0) {
        
        url = [UserCenterUrl shareInstance].URL_API_TEACHER;
        
    }else if (tag == 1){
        
        url = [UserCenterUrl shareInstance].URL_API_ACTIVITY_RULE;
   
    }else if (tag == 2){
        
        url = [UserCenterUrl shareInstance].URL_API_NEWS;
        [params setObject:@(4) forKey:@"type"];
    }
    
    
    [manager POST:url parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            NSArray * array = responseObject[@"data"];
            NSMutableArray * temp = [NSMutableArray array];
            
            for (NSDictionary * item in array) {
                
                if (tag == 0) {
                    
                    TeacherIndexModel * model = [TeacherIndexModel initWithDictionary:item];
                    
                    [temp addObject:model];
                    
                }else if (tag == 1){
                    
                    NSString * url = item[@"url"];
                    
                    [temp addObject:url];
                    
                }else if (tag == 2){
                    
                    NewsIndexModel * model = [NewsIndexModel initWithDictionary:item];
                    
                    [temp addObject:model];
                }
                
            }
            
            if (block)
                block(SUCCESS,temp);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,nil);
        }
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,nil);
    }];
    
}

+ (void)requestApiConfigureEnrollsBlock:(void(^)(NSString *msg,NSNumber * total))block{
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    [manager POST:[UserCenterUrl shareInstance].URL_API_CONFIGURE_ENROLLS parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            NSNumber * total = responseObject[@"data"][@"total"];

            if (block)
                block(SUCCESS,total);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,nil);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,nil);
    }];
    
    
}

+(void)requestApiRegisterSignupMobile:(NSString *)mobile
                            full_name:(NSString *)full_name
                               idcard:(NSString *)idcard
                             nickname:(NSString *)nickname
                                vcode:(NSString *)vcode
                           teacher_id:(NSString *)teacher_id
                                Block:(void(^)(NSString *msg,NSString * html5_jump_url))block{
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    NSMutableDictionary * params = [NSMutableDictionary dictionaryWithCapacity:0];

    
    if (mobile.length != 0) {
        
        [params setObject:mobile forKey:@"mobile"];
    }
    
    if (full_name.length != 0) {
        
        [params setObject:full_name forKey:@"full_name"];
    }
    
    if (nickname.length != 0) {
        
        [params setObject:nickname forKey:@"nickname"];
    }
    
    if (idcard.length != 0) {
        
        [params setObject:idcard forKey:@"idcard"];
    }
    
    
    if (vcode.length != 0) {
        
        [params setObject:vcode forKey:@"vcode"];
    }
    
    if (teacher_id.length != 0) {
        
        [params setObject:teacher_id forKey:@"teacher_id"];
    }
    
    NSString * token = [UserCenterHelper shareInstance].token;
    [params setObject:token forKey:@"token"];
    
    NSLog(@"%@",params);
    
    [manager POST:[UserCenterUrl shareInstance].URL_API_REGISTER_SIGNUP parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            NSString * html5_jump_url = responseObject[@"data"][@"html5_jump_url"];
            
            if (block)
                block(SUCCESS,html5_jump_url);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,nil);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,nil);
    }];
}

+ (void)requestApiUserInfoBlock:(void(^)(NSString *msg,UserModel * model))block{
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    NSString * token = [UserCenterHelper shareInstance].token;
    
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setObject:token forKey:@"token"];

     NSLog(@"%@",params);
    
    [manager POST:[UserCenterUrl shareInstance].URL_API_USER_INFO parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            

            UserModel * model = [UserModel initWithDictionary:responseObject[@"data"]];
            [UserCenterHelper shareInstance].userModel = model;
            
             NSLog(@"token:%@",model.token);
            
            NSUserDefaults * defaults=[NSUserDefaults standardUserDefaults];
            [defaults setObject:model.userDic forKey:USER_DIC];
            [defaults synchronize];
            
            
            if (block)
                block(SUCCESS,model);
            
        }else{
            
             [LoginCorrelationHelper loginCorrelationHelperLoginOverTime:[@(sCode) stringValue]];
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,nil);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,nil);
    }];
    
}

+(void)requestApiAreaBlock:(void(^)(NSString *msg,NSArray * array))block{
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    
    
    [manager POST:[UserCenterUrl shareInstance].URL_API_AREA parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            NSArray * array = responseObject[@"data"];
            NSMutableArray * temp = [NSMutableArray array];
            
            for (NSDictionary * item in array) {
                
                CityIndexModel * model = [CityIndexModel initWithDictionary:item];
                
                [temp addObject:model];
                
            }
            
            if (block)
                block(SUCCESS,temp);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,nil);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,nil);
    }];
}

+(void)requestApiTeacherId:(NSString *)Id
                     Block:(void(^)(NSString *msg,TeacherIndexModel * indexModel))block{
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:nil];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", nil];
    manager.requestSerializer.timeoutInterval = 60;
    

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setObject:Id forKey:@"id"];
    
    
    [manager POST:[UserCenterUrl shareInstance].URL_API_TEACHER_INFO parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            

            TeacherIndexModel * model = [TeacherIndexModel initWithDictionary:responseObject[@"data"]];
            
            if (block)
                block(SUCCESS,model);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,nil);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"requestURL:%@",task.currentRequest.URL.absoluteString);
        NSString *msg=[self  returnErrorMsgError:error];
        
        if (block)
            block(msg,nil);
    }];
    
}

+ (void)requestApiConfigutrSignupFormTipsBlock:(void(^)(NSString *msg,ConfigSignupFormTipsModel * indexModel))block{
    
    [CCRequestTool.shared requestWithURL:[UserCenterUrl shareInstance].URL_API_CONFIGURE_SIGNUP_FORM_TIPS type:RequestTypePost params:nil finish:^(BOOL success, id responseObject, NSString *json, NSURLSessionDataTask *task) {
       
        NSInteger sCode = [responseObject[@"code"] integerValue];
        
        if (sCode == 200) {
            
            ConfigSignupFormTipsModel * model = [ConfigSignupFormTipsModel initWithDictionary:responseObject[@"data"]];
            
            if (block)
                block(SUCCESS,model);
            
        }else{
            
            NSString * msg = responseObject[@"msg"];
            
            if (block)
                block(msg,nil);
        }
    
    }];
    
}


@end
